package com.hollysys.hollimsa.biz.istio.destinationrule.controller;


import com.hollysys.hollimsa.biz.istio.destinationrule.domain.DestinationRuleDTO;
import com.hollysys.hollimsa.biz.istio.destinationrule.domain.DestinationRuleDetailDTO;
import com.hollysys.hollimsa.biz.istio.destinationrule.domain.DestinationRuleVO;
import com.hollysys.hollimsa.biz.istio.destinationrule.domain.SimpleDetailDestinationRuleDTO;
import com.hollysys.hollimsa.biz.istio.destinationrule.service.DestinationRuleService;
import com.hollysys.hollimsa.common.result.AjaxObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.util.List;

@RestController
@RequestMapping(value = "/serviceMesh")
@Validated
@Api(tags="istio 组件管理")
public class DestinationRuleController {

    @Autowired
    private DestinationRuleService destinationRuleService;

    /**
     * 获取组件列表
     * @return  创建状态
     */
    @ApiOperation(value = "组件列表",notes = "组件列表")
    @GetMapping(value = "/destinationRule")
    public AjaxObject<List<DestinationRuleDTO>> listDestinationRule() {
        return AjaxObject.customOk("", destinationRuleService.listDestinationRule());
    }

    /**
     *  增加组件
     * @return  创建状态
     */
    @ApiOperation(value = "创建组件",notes = "创建组件")
    @PostMapping(value = "/destinationRule")
    public AjaxObject<Boolean> addDestinationRule(@RequestBody @Validated DestinationRuleVO destinationRuleVO) {
        return AjaxObject.customOk("", destinationRuleService.createOrReplaceDestinationRule(destinationRuleVO));
    }

    /**
     *  编辑组件
     * @return  创建状态
     */
    @ApiOperation(value = "编辑组件",notes = "编辑组件")
    @PutMapping(value = "/destinationRule")
    public AjaxObject<Boolean> editDestinationRule(@RequestBody  @Validated DestinationRuleVO destinationRuleVO) {
        return AjaxObject.customOk("", destinationRuleService.createOrReplaceDestinationRule(destinationRuleVO));
    }

    /**
     *  删除组件
     * @return  创建状态
     */
    @ApiOperation(value = "删除组件",notes = "删除组件")
    @DeleteMapping(value = "/destinationRule/{name}")
    public AjaxObject<Boolean> deleteDestinationRule(@PathVariable @NotBlank  String name) {
        return AjaxObject.customOk("", destinationRuleService.deleteDestinationRule(name));
    }

    /**
     *  获取组件详情
     * @return  创建状态
     */
    @ApiOperation(value = "组件详情",notes = "组件详情")
    @GetMapping(value = "/destinationRule/{name}")
    public AjaxObject<DestinationRuleDetailDTO> getDestinationRuleDetail(@PathVariable @NotBlank String name) {
        return AjaxObject.customOk("", destinationRuleService.getDestinationRuleDetail(name));
    }

    /**
     *  获取组件 name + host + name[]
     * @return  创建状态
     */
    @ApiOperation(value = "组件下拉",notes = "组件下拉")
    @GetMapping(value = "/destinationRule/drData4DropDown")
    public AjaxObject<SimpleDetailDestinationRuleDTO> drData4DropDown() {
        return AjaxObject.customOk("", destinationRuleService.drData4DropDown());
    }
}
